const PubFuc = {
	showToast: (title) => {
		uni.showToast({
			title: title,
			duration: 1500,
			icon: 'none',
		});
	},
	// 秒格式化 00:00 格式
	formatSecond (second){
		var sec = second % 60;
		var min = Math.floor(second / 60);
		if(min.toString().length < 2){
			min = '0' + min;
		}
		if(sec.toString().length < 2){
			sec = '0' + sec;
		}
		return min + ':' + sec
	},
	getDuration(my_time) {
		var days    = my_time / 1000 / 60 / 60 / 24;
		  var daysRound = Math.floor(days);
		  var hours = my_time / 1000 / 60 / 60 - (24 * daysRound);
		  var hoursRound = Math.floor(hours);
		  hoursRound = hoursRound < 10 ? "0" + hoursRound : hoursRound;
		  var minutes = my_time / 1000 / 60 - (24 * 60 * daysRound) - (60 * hoursRound);
		  var minutesRound = Math.floor(minutes);
		  minutesRound = minutesRound < 10 ? "0" + minutesRound : minutesRound;
		  var seconds = my_time / 1000 - (24 * 60 * 60 * daysRound) - (60 * 60 * hoursRound) - (60 * minutesRound);
		  seconds = seconds < 10 ? "0" + parseInt(seconds) : parseInt(seconds);
		   var time = hoursRound + ':' + minutesRound + ':' + seconds;
		  if (hoursRound < 1) {
			  time = minutesRound + ':' + seconds;
		  }
		 
		  return time;
	
	},
	
	// 格式化时间戳
	formatTime: (value) => {
	    var value = String(value);
	    function t (v) {
	        return v = v < 10 ? ("0" + v) : v;
	    }
	    String.prototype.ToString = function (value) {
	        var date = new Date(parseInt(this.substring(6, this.length - 2)));
	        value = value.replace("yyyy", date.getFullYear());
	        value = value.replace("yy", t(date.getFullYear().toString().substr(2)));
	        value = value.replace("MM", t(date.getMonth() + 1));
	        value = value.replace("dd", t(date.getDate()));
	        value = value.replace("hh", t(date.getHours()));
	        value = value.replace("mm", t(date.getMinutes()));
	        value = value.replace("ss", t(date.getSeconds()));
	        value = value.replace("ms", date.getMilliseconds())
	        return value;
	    };
	    return value.ToString("yyyy-MM-dd  hh:mm:ss");
	}
}

export default PubFuc